/**
 * Created by WYH on 17/4/20.
 */
angular.module('tribalc').factory('EleStyle', function () {



    function height(eleId ,scale, isNeedLineHeight,limitHight) {
        var eleDom = document.getElementById(eleId);
        var height = eleDom ? eleDom.offsetWidth * scale : 0;
        var style = {};
        if (eleId == 'body') {
            height = document.body.offsetWidth * scale;
        }
        if (isNeedLineHeight) {
            style["line-height"] = height + 'px';
        }
        if(limitHight){
            height = height>limitHight ? height: limitHight
        }
        if (height) {
            style["height"] = height + 'px';
        }
        return style;
    }

    function width(eleId, scaleW, scaleH, isNeedLineHeight) {
        var eleDom = document.getElementById(eleId);
        var style = {};
        var width = eleDom ? eleDom.offsetWidth * scaleW : 0;
        if (eleId == 'body') {
            width = document.body.offsetWidth * scaleW;
        }
        if (scaleH) {
            style['height'] = width * scaleH + 'px';
            if (isNeedLineHeight) {
                style['line-height'] = style['height'];
            }
        }
        if (width) {
            style['width'] = width + 'px';
        }
        return style;

    }


    function lineHeight(eleName, scaleH) {
        var eleDom = document.getElementById(eleName);
        if (!eleDom) {
            eleDom = document.getElementsByClassName(eleName)[0];
        }
        var lineHeight = eleDom.offsetHeight;
        if (scaleH) {
            lineHeight *= scaleH;
        }


        if (lineHeight) {
            return {
                "line-height": lineHeight + 'px'
            }
        }
    }


    return {
        height: height,
        width: width,
        lineHeight: lineHeight
    }
})
